<?php

class Core_Model_Tag_Collection_Keyword extends Dcmp_Model_Collection_Strong {

    public function __construct() {
        parent::__construct();
        $this->setItemClass('tag/keyword');
        $this->from('{t}tag_keyword', 'a')
                ->field('a.*');
    }

    public function joinRecord() {
        $this->innerJoin('{t}tag_searchable', 'b', 'b.tag_id', 'a.id')
                ->field('b.*');
        return $this;
    }

    public function  sortBy($name, $dir) {
        switch($name){
            case 'searchcount':
                return $dir == 'asc'? $this->asc('a.search_count'): $this->desc('a.search_count');
        }
        parent::sortBy($name, $dir);
    }

    public function filterBy($name, $arg) {
        switch ($name) {
            case 'name':
                $this->like('a.name', ':name:s')->addParameter('name', "%$arg%");
            case 'type':
                $this->eq('b.record_type', ':type:s')->addParameter('type', $arg);
            case 'names':
                $this->contain('a.name', ':names:s')->addParameter('names', $arg);
        }
        return $this;
    }

}